
import threading
import keyboard
import time


stop_thread = False


def worker():
    while not stop_thread:
        time.sleep(1)

    print("线程已经停止")


thread = threading.Thread(target=worker).start()


def stop_thread():
    stop_thread = True


if __name__ == '__main__':

    """测试快捷键是否执行"""

    keyboard.add_hotkey("ctrl+shift+q", stop_thread)

    print("快捷键已设置，按 Ctrl+Shift+Q 停止线程")
    keyboard.wait('ctrl+shift+q')

    print("线程已停止")
